#define DEBUG
#include <cstdio>

using namespace std;

class City {
public:
  int left, in, out;
};

int main() {
#ifdef DEBUG
  freopen("1.in", "r", stdin);
  freopen("1.out", "w", stdout);
#endif

  const int maxn=200, maxm=600;

  static City city[maxn+1];
  int n, m, ans=0;
  scanf("%d %d", &n, &m);
  for (int i=1; i<=n; i++) {
    scanf("%d %d %d", &city[i].left, &city[i].in, &city[i].out);
    ans += city[i].left>0 ? city[i].left*city[i].out : -city[i].left*city[i].in;
  }
  printf("%d", ans);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
